//
//  StoppingTabBarVC.swift
//  TT_Swift
//
//  Created by Lenny on 16/5/11.
//  Copyright © 2016年 Lenny. All rights reserved.
//

import UIKit

class StoppingTabBarVC: UITabBarController {

    //MARK:life cycle
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
//        self.view.backgroundColor = UIColor.colorWithHex()
        setTabBar()
        
        let btn:UIButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
        btn.backgroundColor = UIColor.yellowColor()
        self.view.addSubview(btn)
        btn.addTarget(self, action: "btnAction:", forControlEvents: UIControlEvents.TouchUpInside)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //MARK:event motheds
    func btnAction(sender:UIButton) {
        
        let movingVC:MovingTabBarVC = MovingTabBarVC()
        self.presentViewController(movingVC, animated: true) { () -> Void in
            
        }
    }
    
    //MARK:private motheds
    func setTabBar() {
        
        let vc1 = ViewController()
        let vc2 = ViewController()
        let vc3 = ViewController()
        let vc4 = ViewController()
        self.viewControllers = [vc1,vc2,vc3,vc4]
        let titles:[NSString] = ["路途","优惠","商城","我"]
        for var item:UITabBarItem in self.tabBar.items! {
            
            let index = self.tabBar.items! .indexOf(item)
            item.title = titles[index!] as String
            item.setTitleTextAttributes([NSForegroundColorAttributeName:WL_S_Bar_H_Color,
                    NSFontAttributeName:UIFont.systemFontOfSize(15)],forState: UIControlState.Selected)
            item.setTitleTextAttributes([NSForegroundColorAttributeName:WL_S_Bar_N_Color,
                NSFontAttributeName:UIFont.systemFontOfSize(15)], forState: UIControlState.Normal)
            
            let imageStr:String = "icon_tabbar_\(index!)_normal"
            let selectImgStr:String = "icon_tabbar_\(index!)_select"
            
            NSLog(imageStr)
            NSLog("\(index!)")
            item.image = UIImage(named: imageStr)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            item.selectedImage = UIImage(named: selectImgStr)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        }
        
        //设置tabbar的样式
        setTabBarStyle()
        
        //设置navibar的样式
        setNaviBarStyle()
    }
    
    func setTabBarStyle() {
        
        self.tabBar.backgroundImage = UIColor.colorToImage(UIColor.whiteColor())
        self.tabBar.shadowImage = UIColor.colorToImage(WL_Line_Color)
    }

    func setNaviBarStyle() {
        
        UINavigationBar.appearance().setBackgroundImage(UIColor.colorToImage(WL_Top_Color), forBarMetrics: UIBarMetrics.Default)
        UINavigationBar.appearance().shadowImage = UIImage()
        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]
        UINavigationBar.appearance().tintColor = UIColor.whiteColor()
    }
}
